import 'package:flutter/material.dart';

class MusicProgress extends StatelessWidget {
  final Duration total;
  final Duration curPosition;

  const MusicProgress({
    super.key,
    this.total = Duration.zero,
    this.curPosition = Duration.zero,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 20),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          /// start time
          Text(_formatTime(curPosition)),

          /// shuffle icon
          const Icon(Icons.shuffle),

          /// repeat icon
          const Icon(Icons.repeat),

          /// end time
          Text(_formatTime(total)),
        ],
      ),
    );
  }

  /// 格式化对应的显示时间
  String _formatTime(Duration duration) {
    var second = duration.inSeconds.remainder(60).toString().padLeft(2, '0');
    var resultTime = '${duration.inMinutes}:$second';

    return resultTime;
  }
}
